package scala.collection.mutable

import scala.collection.mutable

/**
 * 可变map
 */
object MapTest {
  def main(args: Array[String]): Unit = {
    //可变集合
    val map = mutable.Map("A" -> 2, "B" -> 3, "C" -> 9)
    //增加数据
    map.+=("d" -> 7)
    map.+=(("e", 5))
    println(map)

    val map1 = map.+(("f", 29))
    println("map:", map)
    println("map1:", map1)

    map.put("g", 7)
    println("map:", map)

    val map2: Option[Int] = map.put("k", 89)
    println(map2.getOrElse(0))
    println("map2:", map2)

    //删除数据
    map.-=("a", "b")
    println(map)
    map.remove("c")
    println(map)

    //修改数据
    map.update("d", 44)
    println(map)
    map("g") = 5
    println(map)
  }

}
